{% extends 'base.html' %}
{% block content %}
<html>
<head>
    <title>测试用例</title>
    <script type="text/javascript" src="{{url_for('static',filename='tiaoshi_result/testcase.js')}}"></script>
    <link rel="stylesheet" type="text/css" href="{{url_for('static',filename='tiaoshi_result/testcase.css')}}">
    <script type="text/javascript">
        function delcase(obj) {
            var cell1 = obj.parentNode.parentNode.children[1];
            var ids = cell1.innerHTML;
            var data = {'id':ids};
            $.ajax({
                type:'GET',
                url:"{{url_for('delete_case')}}",
                data:data,
                dataType:'json',
                success: window.location.reload()
            })
        }
        function do_many_case() {
            var data = [];
            $(function () {
                $('#cases').find(':checkbox:checked').each(function () {
                    var id_num = $(this).parent().next().text();
                    var case_name = $(this).parent().next().next().text();
                    var server = $(this).parent().next().next().next().text();
                    var way = $(this).parent().next().next().next().next().text();
                    var request_method = $(this).parent().next().next().next().next().next().text();
                    var data_type = $(this).parent().next().next().next().next().next().next().text();
                    var data_i = $(this).parent().next().next().next().next().next().next().next().text();
                    var check = $(this).parent().next().next().next().next().next().next().next().next().text();
                    var is_base = $(this).parent().next().next().next().next().next().next().next().next().next().text();
                    data.push({'id_num':id_num,
                    'case_name':case_name,
                    'server':server,
                    'way':way,
                    'request_method':request_method,
                    'data_type':data_type,
                    'data_i':data_i,
                    'check':check,
                    'is_base':is_base});
                });
                var data_i = {};
                var num = data.length;
                for(var i=0;i<data.length;i++){
                    var ki = i.toString();
                    data_i[ki]=data[i];
                }
                data_i['len']=num;
                $.ajax({
                        type:'GET',
                        url:"{{url_for('do_many_case')}}",
                        data:JSON.stringify(data_i),
                        dataType:'json',
                        async:true
                    })
            });
        }
    </script>
</head>
<form class="form_case" action="{{ url_for('add_testcase')}}" method="POST" id="add_testcase">
    <div id="new_window">
        <h2>新增用例</h2>
        <p>项目名称
            <select name="project_name">
                {% for project in projects %}
                <option value="{{project.project_name}}">{{project.project_name}}</option>
                {% endfor %}
            </select>
        </p>
        <p>模块名称
            <select name="model_name">
                {% for module in modules %}
                <option value="{{module.module_name}}">{{module.module_name}}</option>
                {% endfor %}
            </select>
        </p>
        <p>用例编号           <input type="text" size="50" name="num"></p>
        <p>用例名称           <input type="text" size="50" name="names"></p>
        <p>服务器名称或IP     <input type="text" size="50" name="server"></p>
        <p>路径               <input type="text" size="50" name="way"></p>
        <p>接口参数           <textarea  cols="50" name="data" class="datas"></textarea></p>
        <p>检查点             <input type="text" size="50" name="check"></p>
        <p>请求方式
            <select name="request_method">
                <option value="POST">POST</option>
                <option value="GET">GET</option>
                <option value="PUT">PUT</option>
                <option value="DELETE">DELETE</option>
            </select>
        </p>
        <p>数据类型
            <select name="data_i">
                <option value="DATA">DATA</option>
                <option value="FILE">FILE</option>
                <option value="FORM">FORM</option>
            </select>
        </p>
        <p>是否作为基础数据
            <select name="is_base">
                <option value="YES">YES</option>
                <option value="NO" selected="selected">NO</option>
            </select>
        </p>
        <div class="di_buttom">
            <input  id="sub" type="submit" value="提交" class="di_buttom">
            <input  id="close" type="button" value="关闭" onclick="closewin()" class="di_buttom">
        </div>
    </div>
</form>
<form class="form_case" action="{{ url_for('editor')}}" method="POST" id="editor_testcase">
    <div id="editor_window">
        <h2>编辑用例</h2>
        <p>项目名称
            <select name="project_name1">
                {% for project in projects %}
                <option value="{{project.project_name}}">{{project.project_name}}</option>
                {% endfor %}
            </select>
        </p>
        <p>模块名称
            <select name="module_name1">
                {% for module in modules %}
                <option value="{{module.module_name}}">{{module.module_name}}</option>
                {% endfor %}
            </select>
        </p>
        <p>用例编号           <input type="text" size="50" name="num1"></p>
        <p>用例名称           <input type="text" size="50" name="names1"></p>
        <p>服务器名称或IP     <input type="text" size="50" name="server1"></p>
        <p>路径               <input type="text" size="50" name="way1"></p>
        <p>接口参数           <textarea  cols="50" name="data1" class="datas"></textarea></p>
        <p>检查点             <input type="text" size="50" name="check1"></p>
        <p>请求方式
            <select name="request_method1">
                <option value="POST">POST</option>
                <option value="GET">GET</option>
                <option value="PUT">PUT</option>
                <option value="DELETE">DELETE</option>
            </select>
        </p>
        <p>数据类型
            <select name="data_i1">
                <option value="DATA">DATA</option>
                <option value="FILE">FILE</option>
                <option value="FORM">FORM</option>
            </select>
        </p>
        <p>是否作为基础数据
            <select name="is_base1">
                <option value="YES">YES</option>
                <option value="NO" selected="selected">NO</option>
            </select>
        </p>
        <div class="di_buttom">
            <input id="sub1" type="submit" value="提交" class="di_buttom">
            <input id="close1" type="button" value="关闭" onclick="closewin_editor()" class="di_buttom">
        </div>
    </div>
</form>
<form class="form_case" action="{{ url_for('do_case')}}" method="POST" id="do_case">
    <div id="do_window">
        <h2>调试</h2>
        <p>项目名称
            <select name="project_name2">
                {% for project in projects %}
                <option value="{{project.project_name}}">{{project.project_name}}</option>
                {% endfor %}
            </select>
        </p>
        <p>模块名称
            <select name="module_name2">
                {% for module in modules %}
                <option value="{{module.module_name}}">{{module.module_name}}</option>
                {% endfor %}
            </select>
        </p>
        <p>用例编号           <input type="text" size="50" name="num2"></p>
        <p>用例名称           <input type="text" size="50" name="names2"></p>
        <p>服务器名称或IP     <input type="text" size="50" name="server2"></p>
        <p>路径               <input type="text" size="50" name="way2"></p>
        <p>接口参数           <textarea  cols="50" name="data2" class="datas"></textarea></p>
        <p>检查点             <input type="text" size="50" name="check2"></p>
        <p>请求方式
            <select name="request_method2">
                <option value="POST">POST</option>
                <option value="GET">GET</option>
                <option value="PUT">PUT</option>
                <option value="DELETE">DELETE</option>
            </select>
        </p>
        <p>数据类型
            <select name="data_i2">
                <option value="DATA">DATA</option>
                <option value="FILE">FILE</option>
                <option value="FORM">FORM</option>
            </select>
        </p>
        <p>是否作为基础数据
            <select name="is_base2">
                <option value="YES">YES</option>
                <option value="NO" selected="selected">NO</option>
            </select>
        </p>
        <div class="di_buttom">
            <input id="sub2" type="submit" onclick="open_result()" value="执行" class="di_buttom">
            <input id="close2" type="button" value="关闭" onclick="closewin_do()" class="di_buttom">
        </div>
    </div>
</form>
<div class="form_case" id="result_d">
    <h2>调试结果</h2>
    <p class="do_result">项目名称：<nobr id="org_name" style="font-weight: normal"></nobr></p>
    <p class="do_result">模块名称：<nobr id="module_name" style="font-weight: normal"></nobr></p>
    <p class="do_result">用例名称：<nobr id="case_name" style="font-weight: normal"></nobr></p>
    <p class="do_result">开始时间：<nobr style="font-weight: normal"></nobr></p>
    <p class="do_result">结束时间：<nobr style="font-weight: normal"></nobr></p>
    <p class="do_result">状态码：<nobr style="font-weight: normal"></nobr></p>
    <p class="do_result">调试结果：<nobr style="font-weight: normal"></nobr></p>
    <p class="do_result">接口返回：<nobr style="font-weight: normal"></nobr></p><br>
    <p class="do_result">请等待响应结果.....</p><br><br>
    <div class="di_buttom"><input type="button" value="关闭" onclick="close_result()" class="di_buttom"></div>
</div>
<div class="form_case" id="result">
    <h2>调试结果</h2>
    <p class="do_result">项目名称：<nobr style="font-weight: normal">     {{ result.org_name }}</nobr></p>
    <p class="do_result">模块名称：<nobr style="font-weight: normal">     {{ result.module_name }}</nobr></p>
    <p class="do_result">用例名称：<nobr style="font-weight: normal">     {{ result.case_name }}</nobr></p>
    <p class="do_result">开始时间：<nobr style="font-weight: normal">     {{ result.start_time }}</nobr></p>
    <p class="do_result">结束时间：<nobr style="font-weight: normal">     {{ result.end_time }}</nobr></p>
    <p class="do_result">状态码：<nobr style="font-weight: normal">     {{ result.code }}</nobr></p>
    <p class="do_result">调试结果：<nobr style="font-weight: normal">     {{ result.result_case }}</nobr></p>
    <p class="do_result">接口返回：<nobr style="font-weight: normal">     {{ result.text }}</nobr></p><br><br>
    <div class="di_buttom"><input type="button" value="关闭" onclick="close_result()" class="di_buttom"></div>
</div>
<div class="test_case">
    <form id="top_select" action="{{ url_for('selected_top_case')}}"  method="POST">
        项目
        <select name="project_name_case">
            <option value="全部">全部</option>
            {% for project in projects %}
            <option value="{{project.project_name}}">{{project.project_name}}</option>
            {% endfor %}
        </select>
        模块
        <select name="module_name_case">
            <option value="全部">全部</option>
            {% for module in modules %}
            <option value="{{module.module_name}}">{{module.module_name}}</option>
            {% endfor %}
        </select>
        <input type="submit" id="select_top_case" value="查询">
    </form>
    <div class="top_buttom">
        <input id="add_case" type="button" value="新增用例" onclick="openwin()">
        <input id="do" type="button" value="执行" onclick="do_many_case()">
    </div>
    <table id="cases" border="2" cellpadding="8" style="border-collapse: collapse">
        <tr>
            <th style="width: 2%"><input type="checkbox"></th>
            <th style="width: 3%">用例编号</th>
            <th style="width: 4%">用例名称</th>
            <th style="width: 6%">服务器名称或IP</th>
            <th style="width: 8%">路径</th>
            <th style="width: 3%">请求方式</th>
            <th style="width: 3%">数据类型</th>
            <th style="width: 10%">接口参数</th>
            <th style="width: 3%">检查点</th>
            <th style="width: 5%">是否作为基础数据</th>
            <th style="width: 2%">操作</th>
            <th style="width: 2%">项目</th>
            <th style="width: 2%">模块</th>
        </tr>
        {% for case in cases %}
        <tr>
            <td><input name="check" type="checkbox"></td>
            <td id="id_num">{{case.id}}</td>
            <td id="case_name">{{case.name}}</td>
            <td>{{case.IP}}</td>
            <td>{{case.ways}}</td>
            <td>{{case.request_method}}</td>
            <td>{{case.data_i}}</td>
            <td>{{case.data}}</td>
            <td>{{case.check}}</td>
            <td>{{case.is_base}}</td>
            <td style="width: 2%">
                <input type="button" value="编辑" onclick="editor(this)">
                <input type="button" value="删除" onclick="delcase(this)">
                <input type="button" value="调试" onclick="do_case(this)">
            </td>
            <td style="width: 2%">{{p_name.filter_by(id=case.org_id).first()[0]}}</td>
            <td style="width: 2%">{{m_name.filter_by(id=case.module_id).first()[0]}}</td>
        </tr>
    {% endfor %}
    </table>
</div>
</html>
{% endblock %}